function show_order(id){
   // $('#order_list').slideUp();
    //$('#order_info').load('{$siteurl}/index.php?app=order&act=edit&id='+id);
    //alert('index.php?app=order&act=edit&id='+id);
    //window.open('index.php?app=order&act=edit&id='+id);
	location.href='index.php?app=order&act=edit&id='+id;
}
function show_status(id){
    //$('#order_list').slideUp();
    //$('#order_info').load('{$siteurl}/index.php?app=order&act=edit&id='+id);
    //window.open('index.php?app=order&act=order_status&id='+id);
	location.href='index.php?app=order&act=order_status&id='+id;
}
function add_sourcing_item(){
    if($('#fabric_info').val()==''){
        alert('请填写完整信息');
        return false;
    }
    if($('#fabric_shop_id').val()=='0'){
        alert('请正确填写布行');
        return false;
    }
    $('#sourcing_add').attr('disabled','disabled');
    $('#sourcing_item_id').val('');
    var fdata=$('#addsourcing').serialize();
    var order_id=$('#order_id').val();
    var options = {
        url:'index.php?app=order&act=addsourcing&ajax=1',
        type: 'post',
        data:fdata,
        dataType :'json',
        cache:false,
        success: function(json) {
            if(json.done){
                /*
                var item=json.retval;
                var l=$('tr[type="data"]').length;
                var str = '<tr id="tr_sourcing_item_'+item.item_id+'" type="data"><td>'+(l+1)+'</td>';
                str += '<td>'+item.fabric_info+'</td>';
                str += '<td>'+fabrics[item.fabric_shop_id]['fabric_shop_name']+'</td>';
                str += '<td><input  type="button" class="btn-s-1" value="修改" onclick="edit_sourcing_item(\''+item.item_id+'\');"/>&nbsp;<input  type="button" class="btn-s-1" value="确认" onclick="confirm_s_item(\''+item.item_id+'\');"/></td></tr>';
                $('#sourcing_table tr:last').before(str);
                $('#fabric_info').val('');
                $('#fabric_shop_id').val('');
                
            //alert(json.msg);
            */
                update_souring_list(order_id);
                $('#sourcing_add').attr('disabled',false);
                $('#fabric_info').val('');
                $('#fabric_shop_id').val('0');
                $('#fabric_shop_name').val('');
            }
            else{
                $.alert(json.msg);
                $('#sourcing_add').attr('disabled',false);
            }
        },
        error:function(m,s,e){
            alert(m+s+e)
            }
    };
    $.ajax(options);
    // $('#addsourcing').ajaxForm(options);
    return false;
}
function update_souring_list(order_id){
        order_id=order_id || $('#order_id').val();
        //alert(order_id);return false;
        var mainFrame = window.frames["mainFrame"];
	var s_table=document.getElementById('sourcing_table');
	$.ajax({
		url: 'index.php?app=order&act=get_sourcing_list&order_id=' + order_id,
		type: 'GET',
		error: function () {alert('网络连接错误，请稍后再试');},
		success: function (data) {
			$(s_table).find('tr[type="data"]').remove();
                        $(s_table).find('tr:first-child').after(data);
		}
	});
}
function update_order_pics(front,back){
    var mainFrame = window.frames["mainFrame"];
    if(front!=''){
		if (mainFrame != undefined) {
   	 		mainFrame.document.getElementById('front_pic').value=front;
    		mainFrame.document.getElementById('front_image').src=front;
    		mainFrame.document.getElementById('front_image').style.display='';
		} else {
   	 		document.getElementById('front_pic').value=front;
    		document.getElementById('front_image').src=front;
    		document.getElementById('front_image').style.display='';
		}
    }
     if(back!=''){
		if (mainFrame != undefined) {
    		mainFrame.document.getElementById('back_pic').value=back;
    		mainFrame.document.getElementById('back_image').src=back;
    		mainFrame.document.getElementById('back_image').style.display='';
		} else {
    		document.getElementById('back_pic').value=back;
    		document.getElementById('back_image').src=back;
    		document.getElementById('back_image').style.display='';
		}
     }
    window.parent.unblock();
}

function get_order_pics(front,back){
    
}
function update_sourcing_item(id){
    if( $('#fabric_info').val()==''){
        alert('请填写完整信息');
        return false;
    }
    if($('#fabric_shop_id').val()=='0'){
        alert('请正确填写布行');
        return false;
    }
    $('#sourcing_update').attr('disabled','disabled');
    if($('#sourcing_item_id').val()=='') {return false};
    var fdata=$('#addsourcing').serialize();
    var options = {
        url:'index.php?app=order&act=addsourcing&ajax=1',
        type: 'post',
        data:fdata,
        dataType :'json',
        cache:false,
        success: function(json) {
            if(json.done){
                /*
                var item=json.retval;
                var tr=('#tr_sourcing_item_'+item.item_id);
                var tds=$(tr).find('td');
                $(tds[1]).html(item.fabric_info);
                $(tds[2]).html(fabrics[item.fabric_shop_id]['fabric_shop_name']);
                $(tds[3]).html('<input  type="button" class="btn-s-1" value="修改" onclick="edit_sourcing_item(\''+item.item_id+'\');"/>&nbsp;<input  type="button" class="btn-s-1" value="确认" onclick="confirm_s_item(\''+item.item_id+'\');"/></td>');
                $('#sourcing_update').attr('disabled',false);
            //alert(json.msg);*/
                update_souring_list();
                $('#sourcing_update').attr('disabled',false);
            }
            else{
                $.alert(json.msg);
            }
        },
        error:function(m,s,e){
            alert(m+s+e);
            $('#sourcing_update').attr('disabled',false);
        }
    };

    $.ajax(options);
    // $('#addsourcing').ajaxForm(options);
    return false;
}
function edit_sourcing_item(id){
    if(!id) return;
    $('#sourcing_item_id').attr('value',id);
    //$('#sourcing_add').attr('disabled','disabled');
    $('#sourcing_update').attr('disabled','');
    $.getJSON('index.php?app=order&act=get_sourcing_item&ajax=1&id='+id,function(json){
        if(json.done){
            var item=json.retval;
            $('#fabric_info').val(item.fabric_info);
            $('#fabric_shop_id').val(item.fabric_shop_id);
            $('#fabric_shop_name').val(fabrics[item.fabric_shop_id]['fabric_shop_name']);
        }
        else{
            $.alert(json.msg);
        }
    });

}
function del_sourcing_item(id){
    if(!id) return;
    $('#sourcing_item_id').attr('value',id);
    //$('#sourcing_add').attr('disabled','disabled');
    $('#sourcing_update').attr('disabled','');
    $.getJSON('index.php?app=order&act=drop_sourcing_item&ajax=1&id='+id,function(json){
        if(json.done){
            $('#tr_sourcing_item_'+id).remove();
            var item=json.retval;
            $('#fabric_info').val('');
            $('#fabric_shop_id').val('0');
            $('#fabric_shop_name').val('');
        }
        else{
            $.alert(json.msg);
        }
    });

}

function make_upload(belongs,id,callback){
    $.funkyUI({
        url:"index.php?app=comupload&act=upload&ajax=1&belongs="+belongs+'&id='+id+'&jsoncallback='+callback ,//弹出窗口显示的内容，使用iframe
        // OKEvent:okEvent,//okEvent是自定义的确定按钮响应函数，
        css:{
            width:"500",
            height:"210"
        }
    });
}
function add_pigai_att(json){
    $.unfunkyUI();
    append_att('pigai_att',json);

}
function add_zhidan_att(json){
    $.unfunkyUI();
    append_att('zhidan_att',json);

}
function add_hetong_att(json){
    $.unfunkyUI();
    append_att('hetong_att',json);

}
function add_chahuo_att(json){
    $.unfunkyUI();
    append_att('chahuo_att',json);

}
function add_koukuan_att(json){
    $.unfunkyUI();
    append_att('koukuan_att',json);

}
function add_caigou_att(json){
    $.unfunkyUI();
    append_att('caigou_att',json);
}

function append_att(obj,json){
    if(!json.done){
        $.alert(json.msg);
        return;
    }
    location.reload();
    return;
    $(json.retval).each(function(){
        //$('#mainFrame').find(obj).append('<br /><a href="'+this.url+'">'+this.path+"</a>");
        mainFrame.document.getElementById(obj).innerHTML +='<br /><a href="'+this.url+'">'+this.path+"</a>";
    });
}

